<template>
  <div class="photoinfo">
    <van-panel :title="photoinfo.title" :status="'阅读' + photoinfo.click">
      <div class="imgs-box">
        <img
          v-for="(item, index) in thumImages"
          :key="item.id"
          :src="item.src"
          @click="ImagePreview(index)"
          alt=""
        />
      </div>
      <div>{{ photoinfo.content }}</div>
    </van-panel>
    <Comment :id="id"></Comment>
  </div>
</template>
<script>
import { ImagePreview } from 'vant'
import Comment from '@/components/comment'
import { getImageInfo, getThumimages } from '@/api/photos'
export default {
  props: ['id'],
  data: () => ({
    photoinfo: {},
    thumImages: []
  }),
  methods: {
    async getImageInfo() {
      const res = await getImageInfo(this.id)
      console.log(res)
      this.photoinfo = res.data.message
    },
    async getThumimages() {
      const res = await getThumimages(this.id)
      console.log(res)
      this.thumImages = res.data.message
    },
    ImagePreview(startPosition) {
      const images = []
      this.thumImages.forEach(item => {
        if (item.src) {
          images.push(item.src)
        }
      })
      ImagePreview({
        images,
        startPosition
      })
    }
  },
  created() {
    this.getImageInfo()
    this.getThumimages()
  },
  components: {
    Comment
  }
}
</script>
<style lang="less" scoped>
</style>